package com.ins.controller;

import com.ins.common.utils.Result;
import com.ins.model.dto.app.AppOrderDTO;
import com.ins.model.entity.AppOrder;
import com.ins.model.vo.OrderPayVO;
import com.ins.service.AppOrderService;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 * 订单表
 *
 * @author ins
 * @since 2024-05-14
 */
@RestController
@RequestMapping("/order")
public class AppOrderController {

    @Resource
    private AppOrderService appOrderService;

    /**
     * 创建 订单
     *
     * @param dto 订单参数
     * @return {@link Long }订单id
     */
    @PostMapping("/create")
    public Result<OrderPayVO> create(@RequestBody @Validated AppOrderDTO dto) {
        return Result.ok(appOrderService.create(dto));
    }


    /**
     * 根据主键删除订单表
     *
     * @param id 主键
     * @return {@code true} 删除成功，{@code false} 删除失败
     */
    @DeleteMapping("/remove/{id}")
    public Result<Boolean> remove(@PathVariable Serializable id) {
        return Result.ok(appOrderService.removeById(id));
    }


    /**
     * 根据主键更新订单表
     *
     * @param appOrder 订单表
     * @return {@code true} 更新成功，{@code false} 更新失败
     */
    @PutMapping("/update")
    public Result<Boolean> update(@RequestBody AppOrder appOrder) {
        return Result.ok(appOrderService.updateById(appOrder));
    }


    /**
     * 查询所有订单表
     *
     * @return 所有数据
     */
    @GetMapping("/list")
    public Result<List<AppOrder>> list() {
        return Result.ok(appOrderService.list());
    }


    /**
     * 根据订单表主键获取详细信息。
     *
     * @param id appOrder主键
     * @return 订单表详情
     */
    @GetMapping("/getInfo/{id}")
    public Result<AppOrder> getInfo(@PathVariable Serializable id) {
        return Result.ok(appOrderService.getById(id));
    }


    /**
     * 分页查询订单表
     *
     * @param page 分页对象
     * @return 分页对象
     */
    @GetMapping("/page")
    public Result<Page<AppOrder>> page(Page<AppOrder> page) {
        return Result.ok(appOrderService.page(page));
    }
}